package com.bx.implatform.growUp.controller;

import com.bx.implatform.growUp.param.*;
import com.bx.implatform.growUp.result.GrowUpBaseResult;
import com.bx.implatform.growUp.result.GrowUpBaseResultUtils;
import com.bx.implatform.growUp.service.GrowUpApiService;
import com.bx.implatform.kafka.entity.PublishApproveChange;
import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 长大控制器
 */
@RestController
@RequestMapping("/imApi/growUp")
@Tag(name = "长大接口")
@RequiredArgsConstructor
public class GrowUpApiController {

    @Resource
    private GrowUpApiService growUpApiService;


    @PostMapping("/SubCenterMonitor/dispatchApi/getRoads")
    @Operation(summary = "3.1路段列表", description = "查询路段列表")
    public GrowUpBaseResult<JsonNode> getRoads() {
        return GrowUpBaseResultUtils.success(growUpApiService.getRoads());
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getEventTypeList")
    @Operation(summary = "3.2事件类型列表", description = "查询所有事件类型列表")
    public GrowUpBaseResult<JsonNode> getEventTypeList() {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventTypeList());
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getEventCategoryList")
    @Operation(summary = "3.3事件类别列表", description = "查询所有事件类别列表")
    public GrowUpBaseResult<JsonNode> getEventCategoryList() {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventCategoryList());
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getEventList")
    @Operation(summary = "3.4事件列表", description = "查询事件列表")
    public GrowUpBaseResult<JsonNode> getEventList(@Valid @RequestBody GetEventListParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventList(param, null));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getEventDynamicInfoList")
    @Operation(summary = "3.5事件动态信息", description = "查询事件续报信息")
    public GrowUpBaseResult<JsonNode> getEventDynamicInfoList(@RequestParam String eventId) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventDynamicInfoList(eventId));
    }

    @PostMapping(value = "/SubCenterMonitor/dispatchApi/uploadFile", consumes = "multipart/form-data")
    @Operation(summary = "3.6上传文件", description = "上传文件接口,使用form表单。将结果中的url字段添加到具体的业务表单字段\n" +
            "默认上传大小限制50MB。")
    public GrowUpBaseResult<JsonNode> uploadFile(@Parameter(description = "上传的文件", required = true)
                                                 @RequestPart("file") MultipartFile file) {
        return GrowUpBaseResultUtils.success(growUpApiService.uploadFile(file));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/saveEventProgress")
    @Operation(summary = " 3.7保存事件进度", description = "上报事件信息反馈接口")
    public GrowUpBaseResult<JsonNode> saveEventProgress(@Valid @RequestBody SaveEventProgressParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.saveEventProgress(param));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getEventProgressList")
    @Operation(summary = " 3.8获取事件进度列表", description = "事件进度列表查询接口")
    public GrowUpBaseResult<JsonNode> getEventProgressList(@RequestParam String eventId) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventProgressList(eventId));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getEventTypeStatistics")
    @Operation(summary = "3.9获取事件统计", description = "获取事件分组统计数据，按类型分组统计，按时间分组统计")
    public GrowUpBaseResult<JsonNode> getEventTypeStatistics(@Valid @RequestBody GetEventTypeStatisticsParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventTypeStatistics(param));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getAlarmTypeGroup")
    @Operation(summary = " 3.10获取告警类型分组", description = "获取告警类型分组，一级类型")
    public GrowUpBaseResult<JsonNode> getAlarmTypeGroup() {
        return GrowUpBaseResultUtils.success(growUpApiService.getAlarmTypeGroup());
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getAlarmTypeList")
    @Operation(summary = " 3.11获取告警类型", description = "获取告警类型，二级类型")
    public GrowUpBaseResult<JsonNode> getAlarmTypeList() {
        return GrowUpBaseResultUtils.success(growUpApiService.getAlarmTypeList());
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getAlarmList")
    @Operation(summary = "3.12 获取告警列表", description = "获取系统告警数据列表")
    public GrowUpBaseResult<JsonNode> getAlarmList(@Valid @RequestBody GetAlarmListParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.getAlarmList(param));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/saveAlarm")
    @Operation(summary = "3.13上报报警", description = "一键上报")
    public GrowUpBaseResult<JsonNode> saveAlarm(@Valid @RequestBody SaveAlarmParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.saveAlarm(param));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getTrafficStateList")
    @Operation(summary = "  3.14获取路况列表", description = "获取路网交通状态数据")
    public GrowUpBaseResult<JsonNode> getTrafficStateList() {
        return GrowUpBaseResultUtils.success(growUpApiService.getTrafficStateList());
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getEventDivideRoute")
    @Operation(summary = " 3.15获取事件分流路线记录", description = "查询事件的交通分流路线记录")
    public GrowUpBaseResult<JsonNode> getEventDivideRoute(@RequestParam(name = "事件ID", required = false) String eventId,
                                                          @RequestParam(name = "记录id", required = false) String id) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventDivideRoute(eventId, id));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getVideoPlayUrl")
    @Operation(summary = "3.16获取摄像机视频播放地址", description = "返回flv格式的视频流")
    public GrowUpBaseResult<String> getVideoPlayUrl(@RequestParam(name = "设备ID") String deviceId,
                                                    @RequestParam(name = "视频类型 0低码流1高码流") String videoType) {
        return GrowUpBaseResultUtils.success(growUpApiService.getVideoPlayUrl(deviceId, videoType));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getRoleAndResource")
    @Operation(summary = "   3.17获取用户资源", description = "获取系统用户的角色，菜单，权限资源，数据权限路段")
    public GrowUpBaseResult<JsonNode> getRoleAndResource() {
        return GrowUpBaseResultUtils.success(growUpApiService.getRoleAndResource());
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/receiveEmergencyTask")
    @Operation(summary = "3.18事件处置卡反馈", description = "事件处置卡反馈，单兵反馈接收到任务")
    public GrowUpBaseResult<JsonNode> receiveEmergencyTask(@RequestParam(name = "处置卡ID") String taskId) {
        return GrowUpBaseResultUtils.success(growUpApiService.receiveEmergencyTask(taskId));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/revokeAlarm")
    @Operation(summary = "3.19撤销报警", description = "报警未处理前，单兵用户撤销上报报警")
    public GrowUpBaseResult<JsonNode> revokeAlarm(@RequestParam(name = "报警ID") String id) {
        return GrowUpBaseResultUtils.success(growUpApiService.revokeAlarm(id));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getEventNearByCameras")
    @Operation(summary = " 3.20获取事件附近摄像机", description = "获取事件附件摄像机")
    public GrowUpBaseResult<JsonNode> getEventNearByCameras(@RequestParam(name = "事件ID", required = false) String eventId,
                                                            @RequestParam(name = "摄像机数量", required = false) Integer count) {
        return GrowUpBaseResultUtils.success(growUpApiService.getEventNearByCameras(eventId, count));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getUserReportRecordList")
    @Operation(summary = " 3.21查询用户上报记录", description = "查询用户上报记录")
    public GrowUpBaseResult<JsonNode> getUserReportRecordList(@Valid @RequestBody GrowUpBaseParam param) {
        return GrowUpBaseResultUtils.success(growUpApiService.getUserReportRecordList(param));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getUserIdByToken")
    @Operation(summary = "3.22通过token获取用户id", description = "通过token获取用户id")
    public GrowUpBaseResult<String> getUserIdByToken(@RequestParam String token) {
        return GrowUpBaseResultUtils.success(growUpApiService.getUserIdByToken(token));
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/approve/detail")
    @Operation(summary = " 3.26查询审批单", description = "查询发布审批单")
    public GrowUpBaseResult<JsonNode> approveDetail(@RequestParam(name = "审批单id") String id) {
        return GrowUpBaseResultUtils.success(growUpApiService.approveDetail(id));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/approve/access")
    @Operation(summary = "  3.27 同意", description = "审核审批通过")
    public GrowUpBaseResult<JsonNode> approveAccess(@Valid @RequestBody PublishApproveChange param) {
        return GrowUpBaseResultUtils.success(growUpApiService.approveAccess(param));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/approve/reject")
    @Operation(summary = "  3.28 驳回", description = "审核审批驳回")
    public GrowUpBaseResult<JsonNode> approveReject(@Valid @RequestBody PublishApproveChange param) {
        return GrowUpBaseResultUtils.success(growUpApiService.approveReject(param));
    }

    @PostMapping("/SubCenterMonitor/dispatchApi/getVehicleWithVideoList")
    @Operation(summary = " 3.29车载终端列表", description = "获取带车载终端的车辆列表，位置和视频通道")
    public GrowUpBaseResult<JsonNode> getVehicleWithVideoList() {
        return GrowUpBaseResultUtils.success(growUpApiService.getVehicleWithVideoList());
    }

    @GetMapping("/SubCenterMonitor/dispatchApi/getVehiclePosition")
    @Operation(summary = "  3.30获取车辆实时位置", description = "获取指定车辆的实时位置")
    public GrowUpBaseResult<JsonNode> getVehiclePosition(@RequestParam(name = "车辆id") List<String> ids) {
        return GrowUpBaseResultUtils.success(growUpApiService.getVehiclePosition(ids));
    }

}
